package com.UdpRecieve.tool.lisichen;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.File;
import java.io.FileOutputStream;

public class XmlUtils {
    public static void main(String[] args) {
        createSercetXml();
    }

    /**
     * 后期改为传参数
     * @return
     */
    public static String createSercetXml(){
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("SLINFO");
        root.addAttribute("version","1.0.150220");

        Element Item = root.addElement("Item");
        Item.addAttribute("ID","1");
        Item.addAttribute("Name","核心属性");

        Element SX01 = Item.addElement("SX");
        SX01.addAttribute("Name","密级等级");
        SX01.addAttribute("classificationLevel","5");

        Element SX02 = Item.addElement("SX");
        SX02.addAttribute("Name","保密期限");
        SX02.addAttribute("classifiedTime","2016-12-15 09:32:19");
        SX02.addAttribute("classificationPeriod","100000");
        SX02.addAttribute("declassifiedTime","");
        SX02.addAttribute("durationDescription","");

        Element Item02 = root.addElement("Item");
        Item02.addAttribute("ID","2");
        Item02.addAttribute("Name","基本属性");

        Element Item02_SX01 = Item02.addElement("SX");
        Item02_SX01.addAttribute("Name","标志版本");
        Item02_SX01.addAttribute("version","1");

        Element Item02_SX02 = Item02.addElement("SX");
        Item02_SX02.addAttribute("Name","文件起草人");
        Item02_SX02.addAttribute("drafterName","yzw");
        Item02_SX02.addAttribute("drafterID","");


        Element Item02_SX03 = Item02.addElement("SX");
        Item02_SX03.addAttribute("Name","定密责任人");
        Item02_SX03.addAttribute("classifiedPersonName","");
        Item02_SX03.addAttribute("classifiedPersonID","");

        Element Item02_SX04 = Item02.addElement("SX");
        Item02_SX04.addAttribute("Name","文件签发人");
        Item02_SX04.addAttribute("issuerName","");
        Item02_SX04.addAttribute("issuerID","");

        Element Item02_SX05 = Item02.addElement("SX");
        Item02_SX05.addAttribute("Name","定密单位");
        Item02_SX05.addAttribute("ClassifiedOrganizationName","xxx");
        Item02_SX05.addAttribute("ClassifiedOrganizationID","");
        Item02_SX05.addAttribute("count","1");

        Element Item02_SX06 = Item02.addElement("SX");
        Item02_SX06.addAttribute("Name","知悉范围");
        Item02_SX06.addAttribute("accessDescription","xxxx");
        Item02_SX06.addAttribute("accessScopeType","2");
        Item02_SX06.addAttribute("accessListCount","0");


        Element Item02_SX07 = Item02.addElement("SX");
        Item02_SX07.addAttribute("Name","定密依据");
        Item02_SX07.addAttribute("classificationBasisType","0");
        Item02_SX07.addAttribute("classificationBasisDegree","1;");
        Item02_SX07.addAttribute("classificationBasis","秘密条款;");


        Element Item02_SX08 = Item02.addElement("SX");
        Item02_SX08.addAttribute("Name","管理状态");
        Item02_SX08.addAttribute("classificationStatus","1");


        // 5、设置生成xml的格式
        OutputFormat format = OutputFormat.createPrettyPrint();
        // 设置编码格式
        format.setEncoding("UTF-8");
        // 6、生成xml文件
        File file = new File("E:\\2-项目\\4-秘标\\立思辰\\webservice\\webservice\\rss.xml");
        try {
            XMLWriter writer = new XMLWriter(new FileOutputStream(file), format);
            // 设置是否转义，默认使用转义字符
            writer.setEscapeText(false);
            writer.write(document);
            writer.close();
            System.out.println("生成成功");
        } catch (Exception e) {
            System.out.println("生成失败");
            e.printStackTrace();
        }
        return document.asXML();
    }
}
